//
//  LTLDi.m
//  WeiBo
//
//  Created by Apple_Lzzy46 on 16/10/25.
//  Copyright © 2016年 LTL. All rights reserved.
//

#import "LTLDi.h"

@interface LTLDi ()

@property(nonatomic,weak)UIButton *Origina;
@property(nonatomic,weak)UIButton *comments_count;
@property(nonatomic,weak)UIButton *attitudes_count;

@end

@implementation LTLDi

-(instancetype)initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame]) != nil ) {
//        self.backgroundColor= [UIColor blueColor];
        [self setUI];
    }
    return self;
}
//添加及设置控件
-(void)setUI
{
    UIButton *Origina = [[UIButton alloc]init];
    [Origina setImage:[UIImage imageNamed:@"timeline_icon_retweet"] forState:UIControlStateNormal];
    Origina.titleLabel.font = [UIFont systemFontOfSize:12];
    [Origina setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    
    UIButton *comments_count = [[UIButton alloc]init];
    [comments_count setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [comments_count setImage:[UIImage imageNamed:@"timeline_icon_comment"] forState:UIControlStateNormal];
    comments_count.titleLabel.font = [UIFont systemFontOfSize:12];
    
    UIButton *attitudes_count = [[UIButton alloc]init];
    [attitudes_count setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [attitudes_count setImage:[UIImage imageNamed:@"timeline_icon_unlike"] forState:UIControlStateNormal];
    attitudes_count.titleLabel.font = [UIFont systemFontOfSize:12];
    
    [self addSubview:Origina];
    [self addSubview:comments_count];
    [self addSubview:attitudes_count];
    
    self.Origina = Origina;
    self.comments_count = comments_count;
    self.attitudes_count = attitudes_count;
    
    CGRect rect = CGRectMake(0, 0, 5, self.highly);
    for (int i = 1; i<=2; i++) {
        UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"timeline_card_bottom_line_highlighted"]];
        
        image.frame = CGRectOffset(rect, i*(self.width/3-5), 0);
        
        [self addSubview:image];
    }
    
}
//布局
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat w = self.width/3;
    
    [self.Origina mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left);
        make.width.mas_equalTo(w);
        make.height.mas_equalTo(self.highly);
        make.top.equalTo(self.mas_top);
        
    }];
    [self.comments_count mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.Origina.mas_right);
        make.width.mas_equalTo(w);
        make.height.mas_equalTo(self.highly);
        make.top.equalTo(self.mas_top);
        
    }];
    [self.attitudes_count mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.comments_count.mas_right);
        make.width.mas_equalTo(w);
        make.height.mas_equalTo(self.highly);
        make.top.equalTo(self.mas_top);
    }];
}
//设置数据
-(void)setModel:(LTLhomeModel *)model
{
//    [self.Origina setTitle:[NSString stringWithFormat:@"转发 %ld",model.reposts_count] forState:UIControlStateNormal];
//    
//    [self.comments_count setTitle:[NSString stringWithFormat:@"评论 %ld",model.comments_count] forState:UIControlStateNormal];
//    
//    [self.attitudes_count setTitle:[NSString stringWithFormat:@"赞 %ld",model.attitudes_count] forState:UIControlStateNormal];
//    
    [self setButtom:self.Origina Title:@"转发" zhi:model.reposts_count];
    [self setButtom:self.comments_count Title:@"评论" zhi:model.comments_count];
    [self setButtom:self.attitudes_count Title:@"赞" zhi:model.attitudes_count];
    
}

-(void)setButtom : (UIButton *)button Title:(NSString *)title zhi : (NSInteger )zhi
{

    if (zhi > 10000) {
        
        title = [NSString stringWithFormat:@"%f万",(zhi/10000.0)];
        
    } else {
        
        title = [title stringByAppendingFormat:@" %ld",zhi];
        
    }
    
    [button setTitle:title forState:UIControlStateNormal];

}
@end
